<%-- 
    Document   : thi
    Created on : May 15, 2012, 8:34:55 AM
    Author     : 0912153
--%>

<%@page import="java.util.Calendar"%>
<%@page import="java.text.DateFormat"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Date"%>
<%@page import="testonlineconnectdb.TestType"%>
<%@page import="testonlineconnectdb.Question"%>
<%@page import="testonlineconnectdb.TestOnlineConnectDB"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Bài Thi</title>
    </head>
    
        <script>
        var timeout = <%
        request.setCharacterEncoding("UTF-8");
        int timeo = 0;
        String realPath = config.getServletContext().getRealPath("") + "\\OnlineDatabase\\";
        TestOnlineConnectDB cDB = new TestOnlineConnectDB();
        cDB.Connect(realPath + "OnlineDB.accdb");
        ArrayList testTypes = cDB.GetType();
        for(int i =0; i < testTypes.size(); i++)
        {
            TestType temp = (TestType)testTypes.get(i);
            if(temp.name.endsWith(request.getParameter("type")))
            {
                int timetemp = temp.time * 60;
                out.println(Integer.toString(timetemp));
            }
        } 
%>;
        function timer()
        {
            if( --timeout > 0 )
            {
                //document.baithi.clock.value = timeout;
                document.baithi.clock2.value = parseInt(timeout / 60) + " phút";
                document.baithi.clock3.value = timeout % 60 + " giây";
                window.setTimeout( "timer()", 1000 );
            }
            else
            {
                document.forms["baithi"].submit();
            }
        }
        </script>
    <body>
        <p align="center" style="font-size:30px; font-weight: bold;">Bài Thi</p>
        <u><b>Thông tin:</b></u><br/>
        Họ Tên: <% out.println(request.getParameter("hoten")); %><br/>
        Ngày Sinh: <% out.println(request.getParameter("ntns")); %><br/>
        CMND: <% out.println(request.getParameter("cmnd")); %><br/>
        Độ khó: <% out.println(request.getParameter("type")); %><br/><br/><br/>
               
        <%       
        cDB = new TestOnlineConnectDB();
        cDB.Connect(realPath + "OnlineDB.accdb");
        ArrayList ExamQuestion = cDB.GetExamQuestions(1,realPath + "BankQuestion.xml");
        if(ExamQuestion == null)
        {
            System.out.println("table LoaiDeThi is empty");
            return;
        }
        out.println(" <form action=\"kq.jsp\" method=\"POST\" name=\"baithi\" > ");
        Calendar cal = Calendar.getInstance();
        Date datebd = new Date();
        datebd = cal.getTime();
        out.println("<input name=\"ngaybd\" type=\"hidden\" value=\""+ datebd.getTime() + "\" />");
        %>
        
        <p style="font-size:20px" >Thời gian còn lại: <input type="text" name="clock2" value="clock2" style="border:0px solid white">
        <input type="text" name="clock3" value="clock3" style="border:0px solid white"> </p>      
        <%
        out.println("<input name=\"hoten\" type=\"hidden\" value=\""+ request.getParameter("hoten")+ "\" />");
        out.println("<input name=\"ntns\" type=\"hidden\" value=\""+ request.getParameter("ntns")+ "\" />");
        out.println("<input name=\"cmnd\" type=\"hidden\" value=\""+ request.getParameter("cmnd")+ "\" />");
        out.println("<input name=\"type\" type=\"hidden\" value=\""+ request.getParameter("type")+ "\" />");
        
        Integer md = (Integer)(ExamQuestion.get(ExamQuestion.size() - 1));      
        out.println("<input name=\"made\" type=\"hidden\" value=\""+ Integer.toString(md) + "\" />");   
        out.println("<p style=\"font-size:26px\" ><b>Đề: " + Integer.toString(md)+"</b></p>");
        for(int i =0; i < ExamQuestion.size()-1; i++)
        {
            out.println("<U><B>Câu " + Integer.toString(i+1) +":</B></U> ");
            Question temp = (Question)ExamQuestion.get(i);
            out.println(temp.ask +"<br/>");
            out.println("<input name=\"" + temp.code +"\" " + "type=\"radio\" value=\"" + "1\""+ "/>");
            out.println(temp.choice1+"<br/>");
            out.println("<input name=\"" + temp.code +"\" " + "type=\"radio\" value=\"" + "2\""+ "/>");
            out.println(temp.choice2+"<br/>");
            out.println("<input name=\"" + temp.code +"\" " + "type=\"radio\" value=\"" + "3\""+ "/>");
            out.println(temp.choice3+"<br/>");
            out.println("<input name=\"" + temp.code +"\" " + "type=\"radio\" value=\"" + "4\""+ "/>");
            out.println(temp.choice4 + "<br/><br/><br/>");
        }
        out.println(" <input name=\"ButtonS\" value=\"Nộp bài\" type=\"submit\" /> ");
        out.println("</form>");
        %>
        <script>timer();</script>
    </body>
</html>
